<?php
// +----------------------------------------------------------------------
// | 用户自定义函数库
// +----------------------------------------------------------------------

//无需token访问接口
function getNoTokenAction(){

    return $result = [
        'loginorregister',
        'index',
        'sendcode',
        'memberindex',
        'getlabel',
        'findcontenbylabel',
        'modifymemberpassword',
        'login',
        'getlabelnews',
        'ispaymember',
        'memberIndex',
        'ranking',
        'test2',
    ];

}

/**
 * 关闭后台
 */
function closeadmin(){

    require false;

}

/**
 * 格式化时间Y-m-d H:i:s
 */
function dateFormatSecond($time){
    return date("Y-m-d H:i:s",$time);
}

/**
 * 格式化时间Y-m-d
 */
function dateFormat($time){
    return date("Y-m-d",$time);
}

/**
 * api访问
 */
function apiaccess($url, $params = false, $ispost = 0){

    $httpInfo = array ();
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22');
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json; charset=utf-8',
        'Content-Length: ' . strlen($params)
    ));
    if ($ispost) {
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
        curl_setopt($ch, CURLOPT_URL, $url);
    } else {
        if ($params) {
            curl_setopt($ch, CURLOPT_URL, $url . '?' . $params);
        } else {
            curl_setopt($ch, CURLOPT_URL, $url);
        }
    }
    $response = curl_exec($ch);
    if ($response === FALSE) {
        //echo "cURL Error: " . curl_error($ch);
        return false;
    }
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $httpInfo = array_merge($httpInfo, curl_getinfo($ch));
    curl_close($ch);
    return $response;

}